// TOWN SCRIPT
//    Town 3

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

set_terrain(19,29,0);
set_terrain(18,18,0);
set_terrain(16,7,0);
set_terrain(26,29,0);
set_terrain(28,14,0);
set_terrain(30,2,0);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;


//Stop them going back to previous town
beginstate 10;
	message_dialog("You've already explored that section of the caves; heading back there instead of pressing on doesn't make any sense.","");
	block_entry(1);
break;

beginstate 11;
	message_dialog("You finally make it out of these dark caverns. However, your injuries from the fall, and the earlier battle, are taking their toll on you.","If you don't rest soon, you're going to end up dying in these caves...");
		damage_char(1000,15,4);
	move_to_new_town(4,32,40);
break;

//Blocked path
beginstate 12;
	if(get_flag(3,7) == 0) {
		message_dialog("This section of tunnel has been blocked off by rock and rubble - from the looks of it a number of small cavequakes have, over the years, gradually built up on top of each other.","You'll have to find another way out.");
		set_flag(3,7,1);
	}
break;

//Blocked bridge
beginstate 13;
	if(get_flag(3,8) == 0) {
		message_dialog("This bridge has been completely wrecked by a falling boulder. You will have to find another way to cross the river.","");
		set_flag(3,8,1); 
	}	
break;

//INtro
beginstate 14;
if(get_flag(3,0) == 0) {
		message_dialog("This section of cave is much darker than the ones you've just been through - the glowing fungus that lines the ceiling of much of Avernum is thinner here.","However, you can still see a little way ahead - the central passages are still reasonably well-lit. Taking advantage of the light, you look around - the beast is nowhere to be seen. You're safe for now.");
		set_flag(3,0,1);
	}
break;

//Pitch black
beginstate 15;
if(get_flag(3,1) == 0) {
		message_dialog("You creep into these side tunnels, staying alert for any ambushes.","Although you hear nothing nearby, you should proceed with care - these tunnels are completely dark and it'd be easy for something to sneak up on you back here.");
		set_flag(3,1,1);
	}
break;

//Shrooms 1
beginstate 16;
if(get_flag(3,2) == 0) {
		if(get_skill_total(14) < 5) {
			message_dialog("You take a look at the plants growing here and spot a bunch of herbs that you know are useful for making healing potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(3,2,1);
			reward_give(214);
			end();
		}
		if(get_skill_total(14) < 10) {
			message_dialog("You take a look at the plants growing here and spot two bunches of herbs that you know are useful for making healing potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(3,2,1);
			reward_give(214);
			reward_give(214);
			end();
		}
		if(get_skill_total(14) > 10) {
			message_dialog("You take a look at the plants growing here and spot two bunches of herbs that you know are useful for making healing potions, and some toadstools.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(3,2,1);
			reward_give(214);
			reward_give(214);
			reward_give(218);
			end();
		}
	} else {
		message_dialog("You've already searched this patch of herbs and mushrooms - there is nothing else here that looks useful to you.","");
		end();
	}
break;

//growl
beginstate 17;
if(get_flag(3,3) == 0) {
		message_dialog("You make it out of the dark side tunnels and out into the main gallery without incident. However, as you pass into the glow of the ceiling-fungus you hear a loud growl from the north.","Gripping your weapons you scan the caves, but fail to see anything. It would appear that the beast likes to torment it's prey before attacking...");
		set_flag(3,3,1);
	}
break;

//Stopped leaving
beginstate 18;
if(get_flag(3,4) == 0) {
		message_dialog("The cavern here has, once again, been rendered impassable by a mass of rocks and boulders. To the north of the blockade you can see a wider, more-lit cavern.","In order to get there, though, you're going to have to find another way through the caves you're already in.");
		set_flag(3,4,1);
	}
break;

//Pit
beginstate 19;
if(get_flag(3,5) == 0) {
		message_dialog("Here, the cavern floor has fallen away, depositing tonnes of rock into the tunnels below you. You try to peer down into the darkness, but you can't make anything out.","It doesn't really matter anyway - you're going to have to find another way around.");
		set_flag(3,5,1);
	}
break;

//another growl
beginstate 20;
if(get_flag(3,6) == 0) {
		message_dialog("As you're groping your way along this cavern, you freeze - another loud growling reaches your ears from the north, and you hear the sound of claws over stone.","Gripping your weapons, you stand back against the wall, ready to do battle, but nothing ever comes... After another moment or two you begin to inch forward again, weapons still drawn, just in case.");
		set_flag(3,6,1);
	}
break;